<?php
namespace app\login\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Index extends Controller
{
    public function index()
    {
        if(request()->isPost()){
            // $this->success('信息正确，正在为您跳转...','index/index');
            //接收传递的信息
            $name = Request::instance()->post('username');
            $pass = md5(Request::instance()->post('pass'));

            //查询信息
            $list = Db::table('user')->where('username',$name)->find();
            $uname = $list['username'];
            $upass = $list['pass'];
            var_dump($list['id']);
            if(!empty($uname)){
                if($pass == $upass){
                $b = Session::set('id',$list['id']);
                $a = Session::get('id');

                var_dump($a);
                Session::set('name',$list['username']);
                $this->success('登录成功，正在为您跳转...','./index/index');
                } else {
                    $this->error('请输入正确的密码'); 
                }
            }else{
                $this->error('用户名不存在');
            }
        }
        return $this->fetch('index/login');
    }

    public function logoff()
    {
        Session::clear();
        // $this->redirect('index/index');
        $this->success('正在退出...','./index/index');
    }

}


// class Index extends Controller
// {
//     public function index()
//     {
//         if(request()->isPost()){
//             // $this->success('信息正确，正在为您跳转...','index/index');
//             $name = Request::instance()->post('username');
//             $uname = Db::table('user')->where('username',$name)->find();
//             var_dump($uname);
//             if($name == 'zhang'){
//                 $this->success('信息正确，正在为您跳转...','index/index');
//             }else{
//                 $this->error('用户名或者密码错误');
//             }
//         }
//         return $this->fetch('index/login');
//     }

// }
